﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class OrdershioController : ControllerBase
    {
        private readonly BitDbContext _db;

        public OrdershioController(BitDbContext db)
        {
            _db = db;
        }
        /// <summary>
        /// 添加订单
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        [HttpPost]
        public Result AddOrder([FromBody] EM_Ordershipment shipment)
        {
            Result result = new Result();
            _db.EM_Ordershipment.Add(shipment);
            result.Data = _db.SaveChanges();
            return result;
        }
        /// <summary>
        /// 删除订单
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Result DelOrder(Guid Id)
        {
            Result result = new Result();
            EM_Ordershipment? order = _db.EM_Ordershipment.Where(w => w.id == Id).SingleOrDefault();
            if (order != null)
            {
                _db.EM_Ordershipment.Remove(order);
                result.Data = _db.SaveChanges();
            }
            return result;

        }

        public Result StpGet()
        {
             
            Result result = new Result();
            result.Data = _db.EM_Ordershipment.ToList();
            return result;
        }
    }
}
